package nina.yiyou.attendance.s10merge.compute.offgain


import nina.yiyou.attendance.s10merge.compute.AttendDetailMerger

import java.time.LocalDate

class DeltaDayFinder {

  DeltaDayFinder(AttendDetailMerger.PunchDay baseDay, Closure<LocalDate> delta, List<AttendDetailMerger.PunchDay> dayList) {
    _baseDay = baseDay
    _delta = delta
    _dayList = dayList
  }

  Optional<AttendDetailMerger.PunchDay> find() {
    LocalDate date = _delta.call(_baseDay.date())
    def employeeName = { AttendDetailMerger.PunchDay d -> d.employee().name() }

    return _dayList.stream()
        .filter { employeeName(it) == employeeName(_baseDay) }
        .filter { it.date() == date }
        .findAny()
  }

  private final AttendDetailMerger.PunchDay _baseDay
  private final Closure<LocalDate> _delta

  private final List<AttendDetailMerger.PunchDay> _dayList
}
